package com.ssyt.csgl.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.ssyt.csgl.po.Area;
import com.ssyt.csgl.po.AreaExample;
import com.ssyt.csgl.po.City;
import com.ssyt.csgl.po.CityExample;
import com.ssyt.csgl.po.Province;
import com.ssyt.csgl.po.ProvinceExample;
import com.ssyt.csgl.service.AreaService;
import com.ssyt.csgl.service.CityService;
import com.ssyt.csgl.service.ProvinceService;

@Controller
@RequestMapping("/tree/")
public class TreeController {

	@Autowired
	private ProvinceService provinceService;
	@Autowired
	private CityService cityService;
	@Autowired
	private AreaService areaService;
	@RequestMapping("t")
	public ModelAndView tree(){
		ModelAndView maView=new ModelAndView("tree");
		ProvinceExample mtree = new ProvinceExample();
		mtree=null;
		List<Province> z_tree = provinceService.selectProvince(mtree);
		maView.addObject("z_tree", z_tree);
		return maView;
	}
	@RequestMapping("CityJson")
	@ResponseBody
	public List<City> cityTree(Province province){
		System.out.println();
		List<City> listCity=new ArrayList<City>();
		CityExample city=new CityExample();
		city.createCriteria().andProvincecodeLike(province.getCode());
		listCity=cityService.selectCity(city);
		for (City city1 : listCity) {
			System.out.println(city1);
		}
		return listCity;
	}
	@RequestMapping("AreaJson")
	@ResponseBody
	public List<Area> cityTree(City city){
		System.out.println();
		List<Area> listArea=new ArrayList<Area>();
		AreaExample area=new AreaExample();
		area.createCriteria().andCitycodeEqualTo(city.getCode());
		listArea=areaService.selectCity(area);
		
		return listArea;
	}
	
}
